<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title> ${cRoute.id == null ? '添加' : '修改'}路线</title>
    <%@include file="../include/commonFile.jsp" %>
    <script src="//api.map.baidu.com/api?v=2.0&ak=2izIwlMmDVH737ms8m4Y8uHsoxtEIR65"></script>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/ui/activity/publish_form.css">
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <!-- 正文请写在这里 -->
            <div class="add-form-content">
                <form id="myForm" class="layui-form mt20" method="post"
                      action="${ctx}/member/route/saveOrUpdate.do">
                    <input type="hidden" name="id" value="${cRoute.id}"/>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">路线名称<span class="f-verify-red">*</span></label>
                            <div class="layui-input-inline">
                                <input class="layui-input" name="routeName" id="routeName"
                                       style="width: 400px;"
                                       lay-verify="routeName"
                                       placeholder="路线名称"
                                       value="${cRoute.routeName}">
                            </div>
                        </div>
                    </div>
                    <%--                    <c:if test="${!isChild ||isXzgsAdmin}">
                                            <div class="layui-form-item">
                                                <div class="layui-inline">
                                                    <label class="layui-form-label">选择分社</label>
                                                    <div class="layui-input-inline">
                                                        <select name="memberGroupId" lay-verify="memberGroupId" <c:if test="${cRoute.id != null}">disabled=disabled</c:if> >
                                                            <option value="">请选择</option>
                                                            <c:forEach var="memberGroup" items="${memberGroupList}">
                                                                <option value="${memberGroup.id}" ${cRoute.createBy == memberGroup.id ? 'selected="selected"' : ''}>${memberGroup.realname}</option>
                                                            </c:forEach>
                                                        </select>
                                                    </div>
                                                    <div class="layui-form-mid layui-word-aux">选择了分社，表示代表分社添加路线，否则是当前机构添加路线</div>
                                                </div>
                                            </div>
                                        </c:if>--%>
                    <div class="layui-form-item">
                        <%@include file="routeMap.jsp" %>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">路线途径</label>
                            <div class="layui-input-inline">
                                <input class="layui-input" name="routeWay" id="routeWay"
                                       style="width: 600px;"
                                       lay-verify="routeWay"
                                       placeholder="路线途径"
                                       value="${cRoute.routeWay}">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <a href="javascript:void(0)" class="layui-btn layui-btn-danger" lay-submit
                               lay-filter="*">立即提交</a>
                            <a href="${ctx}/member/route/list.do"
                               class="layui-btn layui-btn-primary">取消</a>
                        </div>
                    </div>
            </div>
            </form>
        </div>
        <%@include file="../include/footer.jsp" %>
    </section>
</div>
<script>
    txz.initHeader({
        nav: [{
            name: '路线管理',
            href: '${ctx}/member/route/list.do'
        }, {
            name: '${cRoute.id == null ? '添加' : '修改'}路线',
            curr: true
        }],
        btns: [{
            name: '返回',
            href: 'javascript:history.back();',
            icon: 'back'
        }]
    });
    var form, laydate, element, formcache;
    $(function () {

        var cityVal = "";
        layui.use(['form', 'laydate', 'element'], function () {
            form = layui.form, laydate = layui.laydate, element = layui.element;

            //初始化地图控件
            txz.Map.init({
                layForm: form,
                data: {
                    cityId: '${cRoute.sCityId}',
                    areaInput: '${cRoute.sArea}',
                    place: '${cRoute.sPlace}',
                    lat: '${cRoute.sLat}',
                    lng: '${cRoute.sLng}',
                    cCityId: '${cRoute.cCityId}',
                    cAreaInput: '${cRoute.cArea}',
                    cPlace: '${cRoute.cPlace}',
                    clat: '${cRoute.cLat}',
                    clng: '${cRoute.cLng}'
                }
            });
            //自定义验证规则
            form.verify({
                routeName: function (value) {
                    if (value.trim() == "") {
                        return '路线名不能为空';
                    }
                },
                cLng: function (value) {
                    if (value.trim() == "") {
                        return '终点未标记';
                    }
                },
                sLng: function (value) {
                    if (value.trim() == "") {
                        return '起点未标记';
                    }
                }
            });

            //监听提交
            form.on('submit', function (data) {
                submitForm(data);
            });

        });
    });

    function submitForm(data) {
        txz.submitObject(data.elem, function (callBack) {
            var formData = getFormData();
            var action = $("#myForm").attr("action");
            txz.ajaxRequest({
                method: 'post',
                url: action,
                saveCache: true,
                cacheObj: formcache,
                params: formData,
                callBack: function (res) {
                    typeof callBack === 'function' && callBack();
                    if (res.success) {
                        util.layerMsgSuccess("提交成功", function () {
                            location.href = "${ctx}/member/route/list.do";
                        });
                    } else {
                        util.layerMsgError(res.description)
                    }
                }
            });
        })
    }

    function getFormData() {
        var formData = util.serializeForm($('#myForm').serializeArray());
        return formData;
    }
</script>
</body>
</html>